package com.zxm.sunshineaiary.view.myedittext;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.zxm.sunshineaiary.util.EditTextColorControl;

import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputConnectionWrapper;

public class TestInputConnection extends InputConnectionWrapper {

	EditTextColorControl mEditTextColorControl = null;

	public TestInputConnection(InputConnection target, boolean mutable) {
		super(target, mutable);
		mEditTextColorControl = EditTextColorControl.getIntance();
	}

	@Override
	public boolean commitText(CharSequence text, int newCursorPosition) {
		if (text.equals("{")) {
			System.out.print(newCursorPosition);
		}

//		// �������벢����
//		text = mEditTextColorControl.getColorText(text);
//		List<String> imgCode = getImage(text.toString());
//		getText(text.toString(),imgCode);
		return super.commitText(text, newCursorPosition);
	}

	private List<String> getImage(String str) {
		List<String> s = new ArrayList<String>();
		Pattern p = Pattern.compile("\\[(.*?)\\]");
		Matcher m = p.matcher(str);
		while (m.find()) {
			s.add(m.group(1));
		}
		return s;
	}
}
